package com.swiftride.controller.app;

import com.swiftride.pojo.param.PricingParam;
import com.swiftride.pojo.result.PricingResult;
import com.swiftride.pojo.result.SplitAccountResult;
import com.swiftride.result.R;
import com.swiftride.service.IPricingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.math.BigDecimal;

@Tag(name = "计算价格", description = "计算价格")
@RestController
@RequestMapping("/app/pricing")
public class AppPricingController {

    @Autowired
    private IPricingService pricingService;

    @Operation(summary = "计算价格", description = "计算价格接口")
    @Parameter(name = "param", description = "计算价格参数对象", required = true)
    @PostMapping("/order")
    public R<PricingResult> pricing(@RequestBody @NotEmpty PricingParam param) {
        return R.success(pricingService.pricing(param));
    }

    @Operation(summary = "分账", description = "分账接口")
    @Parameter(name = "realOrderAmount", description = "总金额", required = true)
    @GetMapping("/splitAccount/{realOrderAmount}")
    public R<SplitAccountResult> splitAccount(@PathVariable(value = "realOrderAmount") BigDecimal realOrderAmount) {
        return R.success(pricingService.splitAccount(realOrderAmount));
    }
}
